<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="所属用户:" prop="myUser.nickname.value">
                            <el-input v-model="queryParams.myUser.nickname.value" placeholder="请输入所属用户昵称" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="专家姓名:" prop="realname.value">
                            <el-input v-model="queryParams.realname.value" placeholder="请输入姓名" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="所在单位:" prop="organization.value">
                            <el-input v-model="queryParams.organization.value" placeholder="请输入所在单位" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="专家岗位:" prop="position.value">
                            <el-input v-model="queryParams.position.value" placeholder="请输入专家岗位" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12" v-if="false">
                        <el-form-item label="起步价:" prop="price.value">
                            <el-input v-model="queryParams.price.value" placeholder="请输入起步价" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="省:" prop="province.value">
                            <el-input v-model="queryParams.province.value" placeholder="请输入省" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="市:" prop="city.value">
                            <el-input v-model="queryParams.city.value" placeholder="请输入市价" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="区:" prop="district.value">
                            <el-input v-model="queryParams.district.value" placeholder="请输入区" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="状态:" prop="status.value">
                            <el-select v-model="queryParams.status.value" placeholder="请选择状态" clearable>
                                <el-option v-for="(item, index) in status" :key="index" :label="item.label" :value="item.value" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>


            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="210">
                        <template slot-scope="scope">
                           <div>
                               <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)" v-hasPermi="api.edit">编辑</el-button>
                               <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button>
                               <el-button size="mini" type="text" icon="el-icon-document-checked" @click="handleAudit(scope.row)" v-hasPermi="api.audit">审核记录</el-button>
                           </div>
                            <div>
                                <el-button size="mini" type="text" icon="el-icon-tickets" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button>
                                <el-button size="mini" type="text" icon="el-icon-data-analysis" @click="handleChat(scope.row)" v-hasPermi="api.chat">咨询记录</el-button>
<!--                                <el-button size="mini" type="text" icon="el-icon-document-copy" @click="handleOrder(scope.row)" v-hasPermi="api.order">付费记录</el-button>-->
                                <el-button size="mini" type="text" icon="el-icon-document-copy" @click="handleBuyOrder(scope.row)" v-hasPermi="api.buyorder">付费记录</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </template>
            </qa-table>
            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>
        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? ( findFormData[pk] ? '编辑' : '添加' ) : '详情'" :visible="editOpen" :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData" :disabled="disabled" v-if="editOpen"
                      @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>
        <el-dialog title="审核日志列表" :visible.sync="auditObj.visible"
                   class="dialog-no-pd"
                   width="60%" destroy-on-close append-to-body>
            <div style="height: 70vh;overflow-y: auto" v-if="auditObj.visible">
                <auditList :queryObj="auditObj"></auditList>
            </div>
        </el-dialog>
        <el-dialog title="用户咨询日志" :visible.sync="chatObj.visible"
                   class="dialog-no-pd"
                   width="60%" destroy-on-close append-to-body>
            <div style="height: 70vh;overflow-y: auto" v-if="chatObj.visible">
                <chatList :queryObj="chatObj"></chatList>
            </div>
        </el-dialog>
        <el-dialog title="咨询付费记录" :visible.sync="orderObj.visible"
                   class="dialog-no-pd"
                   width="60%" destroy-on-close append-to-body>
            <div style="height: 70vh;overflow-y: auto" v-if="orderObj.visible">
<!--                <orderList :queryObj="orderObj"></orderList>-->
                <buyOrderList :queryObj="orderObj"></buyOrderList>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
import auditList from '../specialist_audit_log/index'
import chatList from '../specialist_chat_log/index'
import orderList from '../specialist_order/index'
import buyOrderList from '../specialist_buy_order/index'

export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm, auditList, chatList, orderList, buyOrderList },
    data() {
        return {
            // table结构
            pk:'id',
            columns: [
                {
                    visible: true,
                    label: '编号',
                    prop: 'id',
                    width: 60
                },
                {
                    visible: true,
                    label: '所属用户',
                    prop: 'myUser.nickname',
                },
                {
                    visible: true,
                    label: '专家姓名',
                    prop: 'realname',
                },
                {
                    visible: true,
                    label: '封面',
                    prop: 'images',
                    component:'QuickAdminImage',
                },
                {
                    visible: true,
                    label: '所在单位',
                    prop: 'organization',
                },
                {
                    visible: true,
                    label: '专家岗位',
                    prop: 'position',
                },
                {
                    visible: true,
                    label: '单价',
                    prop: 'price',
                    width: 80,
                    overflow: true
                },
                {
                    visible: true,
                    label: '更新时间',
                    prop: 'update_time',
                    width: 120,
                    overflow: true
                },
                {
                    visible: true,
                    label: '状态',
                    prop: 'status',
                    component:'QuickAdminTextColor',
                    formatter: (prop, row) => {
                        let type = ''
                        switch (prop) {
                            case 1:
                                type = 'info'
                                break
                            case 2:
                                type = 'success'
                                break
                            case 3:
                                type = 'warning'
                                break
                        }
                        return {
                            value: prop,
                            type: type,
                            text: row.status_text,
                        }
                    },
                },
                {
                    visible: true,
                    label: '地区',
                    prop: 'province',
                    formatter: (prop, row) => {
                        let arr = [
                            row.province || '',
                            row.city || '',
                            row.district || ''
                        ].filter(el => {
                            return el !== ''
                        })
                        return arr.join(" · ")
                    }
                },
                {
                    visible: true,
                    label: '咨询数',
                    prop: 'chat_count',
                    width: 80,
                    overflow: true
                },
                {
                    visible: true,
                    label: '订单数',
                    prop: 'order_count',
                    width: 80,
                    overflow: true
                },
            ],
            // 接口地址
            api: {
                index: `/admin/sq.specialist/index`,
                find: `/admin/sq.specialist/find`,
                add: `/admin/sq.specialist/add`,
                edit: `/admin/sq.specialist/edit`,
                delete: `/admin/sq.specialist/delete`,
                export: `/admin/sq.specialist/export`,
                status: `/admin/sq.specialist/status`,
                audit: `/admin/sq.specialist_audit_log/index`,
                chat: `/admin/sq.specialist_chat_log/index`,
                order: `/admin/sq.specialist_order/index`,
                buyorder: `/admin/sq.specialist_buy_order/index`,
            },
            editFormParams: {},
            // 搜索表单是否展开
            searchExpand: false,
            // 查询参数
            queryParams: {
                realname: { value:undefined, op: '%like%'},
                organization: { value:undefined, op: '%like%'},
                position: { value:undefined, op: '%like%'},
                price: { value:undefined, op: 'range'},
                status: { value:undefined, op: '='},
                myUser:{ nickname: { value:undefined, op: '%like%'},},
                province: { value:undefined, op: '%like%'},
                city: { value:undefined, op: '%like%'},
                district: { value:undefined, op: '%like%'},
            },
            status:[
               { label: "审核中", value: 1 },
               { label: "已通过", value: 2 },
               { label: "已拒绝", value: 3 },
            ],
            auditObj: {
                visible: false,
                spec_id: ''
            },
            chatObj: {
                visible: false,
                spec_id: ''
            },
            orderObj: {
                visible: false,
                spec_id: ''
            }
        }
    },

    methods: {
        handleAudit(row) {
            this.auditObj = {
                visible: true,
                spec_id: row.id
            }
        },
        handleChat(row) {
            this.chatObj = {
                visible: true,
                spec_id: row.id
            }
        },
        handleOrder(row) {
            this.orderObj = {
                visible: true,
                spec_id: row.id
            }
        },
        handleBuyOrder(row) {
            this.orderObj = {
                visible: true,
                spec_id: row.id
            }
        }
    }
}
</script>
